{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<!-- search start -->	
							{$searchGroup}
							<!-- search end -->

						</div>
						<div id="CodeGoodsTableToolbar" role="group">
							<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
								<i class="fa fa-plus"></i>&nbsp;添加
							</button>
						
							<button type="button" id="update" class="btn btn-primary button-margin" onclick="CodeGoods.update()">
								<i class="fa fa-edit"></i>&nbsp;修改
							</button>
					
							<button type="button" id="delete" class="btn btn-danger button-margin" onclick="CodeGoods.delete()">
								<i class="fa fa-trash"></i>&nbsp;删除
							</button>					
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	{$formStr}
	
	
	CodeGoods.buttonFormatter = function(value,row,index) {
		if(value){
			var str= '';
			
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+value+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;'
			
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+value+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;'
			
			return str;
		}
	}
	
	{$queryParam}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.add = function (value) {
		var index = layer.open({type: 2,title: '创建数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/FormData/add/extend_id/{$extend_id}'});
		this.layerIndex = index;
	}


	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '编辑数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/FormData/update/extend_id/{$extend_id}/data_id/'+value});
		}else{
			if (this.check()) {
				var idx = '';

				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.data_id;
				});

				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '编辑数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/FormData/update/extend_id/{$extend_id}/data_id/'+idx});
				this.layerIndex = index;
			}
		}
	}
	
	CodeGoods.view = function (value) {

		if (this.check()) {
			var idx = '';

			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.data_id;
			});

			idx = idx.substr(1);
			if(idx.indexOf(",") !== -1){
				Feng.info("请选择单条数据！");
				return false;
			}
			var index = layer.open({type: 2,title: '查看数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/FormData/view/extend_id/{$extend_id}/data_id/'+idx});
			this.layerIndex = index;
		}
		
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/FormData/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('data_ids', value);
				ajax.set('extend_id', '{$extend_id}');
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';

				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.data_id;
				});

				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/FormData/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg);
						}
					});
					ajax.set('data_ids', idx);
					ajax.set('extend_id', '{$extend_id}');
					ajax.start();
				});
			}
		}
	}
	

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/FormData/index/extend_id/{$extend_id}.html",defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
		var fieldList = '{$searchList}';
		fieldList = eval('(' + fieldList + ')');
		for(var p in fieldList){
			if(fieldList[p]['type'] == 7){
				laydate.render({elem: '#'+fieldList[p]['field'],type: 'datetime',range:true});
			}
			
			if(fieldList[p]['type'] == 12){
				laydate.render({elem: '#'+fieldList[p]['field'],type: 'datetime',range:true});
			}
		}
	});
</script>
{/block}